package com.stlm2.dems.dao.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.stlm2.dems.entity.PurchaseOrder;
import com.stlm2.dems.dao.PurchaseOrderDao;
import com.stlm2.core.base.impl.BaseDaoImpl;

import java.util.HashMap;
import java.util.Map;

@Repository("purchaseOrderDao")
public class PurchaseOrderDaoImpl extends BaseDaoImpl<PurchaseOrder> implements PurchaseOrderDao {

    @Override
    public PurchaseOrder getByCode(String code) {
        if(StringUtils.isBlank(code))
            return null;

        return selectOne("getByCode", code);
    }

    @Override
    public PurchaseOrder getByIdForUpdate(Integer id) {
        if(id <= 0)
            return null;

        return selectOne("getByIdForUpdate", id);
    }

    @Override
    public Integer purchaseOrderNum(Integer userId, Integer orderStateValue) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("userId",userId);
        map.put("orderStateValue",orderStateValue);
        return (Integer) _selectOne("purchaseOrderNum",map);
    }

    @Override
    public Integer purchaseOrderNum2(Integer userId) {
        return (Integer) _selectOne("purchaseOrderNum2",userId);
    }
}